package com.github.aloxc.plugin.restplus.entity;

import com.github.aloxc.plugin.DonotGuard;
import com.intellij.ide.util.PropertiesComponent;

import java.util.Arrays;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * url列表分组方式
 * @author leero
 */
@DonotGuard
public enum Group{
    /**
     * 模块
     */
    @DonotGuard
    MODULE("module"),

    /**
     * 方法
     */
    @DonotGuard
    METHOD("method");
    private Group(String type) {
        this.type = type;
    }

    public String getType() {
        return type;
    }

    private String type;

    private static Map<String, Group> groupMap = Arrays.stream(Group.values()).collect(Collectors.toMap(k->k.getType().toLowerCase(), v->v));
    public static Group getByType(String type){
        if(type == null){
            return MODULE;
        }
        return groupMap.get(type.toLowerCase());
    }

    public static Group get(){
        PropertiesComponent instance = PropertiesComponent.getInstance();
        String group = instance.getValue(Group.class.getName());
        return getByType(group);
    }

    public static void set(Group group){
        PropertiesComponent instance = PropertiesComponent.getInstance();
        instance.setValue(Group.class.getName(),group.getType());
    }
}